package com.cssy.yd.logic.dao.impl;

import com.cssy.yd.logic.dao.LogicWhCheckDAO;
import com.cssy.yd.logic.entity.LogicWhCheckDO;
import com.cssy.yd.logic.entity.LogicWhCheckDetailsDO;
import com.plat.helper.SearchConditions;

import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

/**
 * 数据访问对象实现类
 * @since 2013-09-02
 */
public class LogicWhCheckDAOImpl extends SqlMapClientDaoSupport implements LogicWhCheckDAO {

    /**
     * 插入数据
     * @param logicWhCheckDO
     * @return 插入数据的主键
     */
    public String insertLogicWhCheckDO(LogicWhCheckDO logicWhCheckDO) throws DataAccessException {
    	logicWhCheckDO.setVersion(1);
        Object id = getSqlMapClientTemplate().insert("LogicWhCheck.insert", logicWhCheckDO);
        return (String) id;
    }

    /**
     * 统计记录数
     * @param logicWhCheckDO
     * @return 查出的记录数
     */
    public Integer countLogicWhCheckDOByExample(LogicWhCheckDO logicWhCheckDO) throws DataAccessException {
        Integer count = (Integer) getSqlMapClientTemplate().queryForObject("LogicWhCheck.countByDOExample", logicWhCheckDO);
        return count;
    }

    /**
     * 更新记录
     * @param logicWhCheckDO
     * @return 受影响的行数
     */
    public Integer updateLogicWhCheckDO(LogicWhCheckDO logicWhCheckDO) throws DataAccessException {
    	logicWhCheckDO.setVersionbt(logicWhCheckDO.getVersion());
    	logicWhCheckDO.setVersion(logicWhCheckDO.getVersion()+1);
    	int result = getSqlMapClientTemplate().update("LogicWhCheck.update", logicWhCheckDO);
        return result;
    }

    /**
     * 获取对象列表
     * @param logicWhCheckDO
     * @return 对象列表
     */
    @SuppressWarnings("unchecked")
    public List<LogicWhCheckDO> findListByExample(LogicWhCheckDO logicWhCheckDO) throws DataAccessException {
        List<LogicWhCheckDO> list = getSqlMapClientTemplate().queryForList("LogicWhCheck.findListByDO", logicWhCheckDO);
        return list;
    }

    /**
     * 根据主键获取logicWhCheckDO
     * @param id
     * @return logicWhCheckDO
     */
    public LogicWhCheckDO findLogicWhCheckDOByPrimaryKey(String id) throws DataAccessException {
        LogicWhCheckDO logicWhCheckDO = (LogicWhCheckDO) getSqlMapClientTemplate().queryForObject("LogicWhCheck.findByPrimaryKey", id);
        return logicWhCheckDO;
    }

    /**
     * 删除记录
     * @param id
     * @return 受影响的行数
     */
    public Integer deleteLogicWhCheckDOByPrimaryKey(String id) throws DataAccessException {
        Integer rows = (Integer) getSqlMapClientTemplate().delete("LogicWhCheck.deleteByPrimaryKey", id);
        return rows;
    }

    @Override
    public List<LogicWhCheckDO> find(SearchConditions scs) throws DataAccessException{
		List<LogicWhCheckDO> list = getSqlMapClientTemplate().queryForList("LogicWhCheck_ex.find", scs);
   		   return list;
    }
    
	@Override
    public Integer count(SearchConditions scs) throws DataAccessException {		
		 Integer count = (Integer) getSqlMapClientTemplate().queryForObject("LogicWhCheck_ex.count", scs);
  	      return count;
  	}

	@Override
	public LogicWhCheckDO findLastedByOricode(String oriCode)
			throws DataAccessException {
		LogicWhCheckDO logicWhCheckDO = (LogicWhCheckDO) getSqlMapClientTemplate().queryForObject("LogicWhCheck_ex.findLastedByOricode", oriCode);
        return logicWhCheckDO;
	}

	@Override
	public List<LogicWhCheckDetailsDO> findListDetatils(SearchConditions scs)
			throws DataAccessException {
		List<LogicWhCheckDetailsDO> list = getSqlMapClientTemplate().queryForList("LogicWhCheck_ex.findListDetatils", scs);
	   		return list;
	}

	@Override
	public Integer findListDetatilsCount(SearchConditions scs)
			throws DataAccessException {
   		Integer count = (Integer) getSqlMapClientTemplate().queryForObject("LogicWhCheck_ex.findListDetatilsCount", scs);
   		return count;
	}
}